package config

import (
	"fmt"

	"github.com/spf13/viper"
)

var C *Config

type Config struct {
	Name    string
	Url     string
	LogFile string
	Send    ConfigSend
	Users   []ConfigUsers
	Urls    []ConfigUrls
}

type ConfigSend struct {
	Email   string
	Token   string
	Subject string
	Host    string
	Port    int
}

type ConfigUsers struct {
	Email  string
	Author string
}

type ConfigUrls struct {
	Url    string
	Key    string
	Time   uint64
	Remark string
	Cmd    string
}

func ConfigInit() {
	viper.SetConfigFile("./config.yaml")
	if err := viper.ReadInConfig(); err != nil {
		// 处理配置文件读取错误
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	// 将配置信息 反序列化到结构体中
	if err := viper.Unmarshal(&C); err != nil {
		// 处理配置信息 反序列化错误
		panic(fmt.Errorf("unable to decode into struct, %v", err))
	}

	fmt.Println(C)
}
